<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>新增</title>
    <script
            src="https://code.jquery.com/jquery-3.3.1.min.js"
            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
            crossorigin="anonymous">
    </script>
</head>
<body style="text-align: center">
<form id="myform" method="post"
              action="/lanxum/gateway/system/sys-module/addModule"
              enctype="application/json">
    parentId1: <input type="text" name="parentId"><br>
    code: <input type="text" name="code"><br>
    name: <input type="text" name="name"><br>
    url: <input type="text" name="url"><br>
    sort: <input type="text" name="sort"><br>
    type: <input type="text" name="type"><br>
    status: <input type="text" name="status"><br>
    moduleLevel1: <input type="text" name="moduleLevel"><br>
    token1: <input type="text" id="token" name="token" style="height:50px;"><br>
    <input type="button" onclick="mySubmit()"  value="提交">
</form>

</body>
<script type="application/javascript">
    //发送表单ajax请求
    function mySubmit(){
        $.ajax({
            url:"/lanxum/gateway/system/sys-module/addModule",
            type:"POST",
            data:JSON.stringify($('form').serializeObject()),
            contentType:"application/json",  //缺失会出现URL编码，无法转成json对象
            success:function(){
                alert("成功");
            }
        });
    }

    /**
     * 自动将form表单封装成json对象
     */
    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [ o[this.name] ];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
</script>
</html>